package cn.shengongying.api.controller;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;

/**
 * author: RXK
 * date: 2022/1/6 星期四
 * desc:
 */
public abstract class BaseController {

    protected  Logger logger = LoggerFactory.getLogger(BaseController.class);


    protected String getBody(HttpServletRequest request) throws IOException {
        byte[] bytes = IOUtils.toByteArray(request.getInputStream());
        String body = new String(bytes, StandardCharsets.UTF_8);
        logger.info("接收到微信支付的回调内容:{}", body);
        return body;
    }

    protected boolean isRequestSuccess(Map<String,String> data) {
        String resultCode = data.get("return_code");
        return "SUCCESS".equals(resultCode);
    }
}
